﻿package KK.GameBase{ 
	import flash.utils.Dictionary;

	public class MessageQueue implements IMessageQueue{
		protected var MsgFollowers:Dictionary;
		public function MessageQueue()
		{
			MsgFollowers=new Dictionary;
			init(); 
		}
		private function init():void
		{
			
		}
		//发布消息
		public function Publish(message:MSGEvent):void
		{ 
			if(MsgFollowers[message.type]!=null)
			{
				var Queue:Dictionary=MsgFollowers[message.type];
				var key:*;
				for(key in Queue)
				{
					Queue[key].Update(message);
				}
			}
			
		} 
		
		//关注这个消息
		public function  AttentionMessage(message:String,Followers:IMessageFollowers):void
		{
			var Queue:Dictionary=MsgFollowers[message];
			if(Queue==null)
			{
				MsgFollowers[message]=new Dictionary;
				Queue=MsgFollowers[message];
			}
			Queue[Followers]=Followers;
		}
		
		public function RemoveMessage(message:String,Followers:IMessageFollowers):void
		{
			if(MsgFollowers[message]!=undefined)
			{
				delete MsgFollowers[message][Followers];
			}
		}
	}
}